<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加交易</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  
    {include file="public/css"}
    {include file="public/js"}
</head>
<body>
<!-- 后台面包屑导航 -->
{:get_admin_breadcrumb()}
<blockquote class="layui-elem-quote" style="margin-top:10px;">说明：交易</blockquote>

<div class=""  style="padding:20px">

  
<form class="layui-form"  method="post" >

               <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 分类</label>
                {:get_cate('guarantee_category')}
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 交易标题</label>
                <div class="layui-input-inline" style="width:500px">
                  <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="" class="layui-input"  value="">
                </div>
                 <div class="layui-form-mid layui-word-aux"><span class="orange">*</span> 必填</div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 发布用户 </label>
                <div class="layui-input-inline">
                  <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="" class="layui-input" value="" id="username">
                </div>
                  <div class="layui-input-inline">
                   <a href="javascript:;"  class="layui-btn layui-btn layui-btn-normal" id="choose-user">选择用户</a>
                 </div>
                 <div class="layui-form-mid layui-word-aux">{:about('必须是本站用户')}</div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 发布者身份 </label>
                <div class="layui-input-block" >
                <input type="radio" name="id_type" lay-filter="id_type" value="0" title="买家" checked>
                <input type="radio" name="id_type" lay-filter="id_type" value="1"  title="卖家">
           
                </div>
                 <div class="layui-form-mid layui-word-aux"></div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 交易价格</label>
                <div class="layui-input-inline" style="width:150px;">
                  <input type="text" name="price" id="price" lay-verify="price" autocomplete="off" placeholder="" class="layui-input" value=""  maxlength="10">
                </div>
                 <div class="layui-form-mid layui-word-aux">元</div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 中介费 </label>
                <div class="layui-input-block" >
                <input type="radio" name="fee_type" lay-filter="fee_type" value="1" title="买家全付 " checked>
                <input type="radio" name="fee_type" lay-filter="fee_type" value="2"  title="卖家全付 ">
                <input type="radio" name="fee_type" lay-filter="fee_type" value="3" title="双方各付一半" >
                </div>
                 <div class="layui-form-mid layui-word-aux"></div>
              </div>
        
              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"> 担保内容</label>
                <div class="layui-input-block" style="padding:20px">
                 {form:ueditor name="content"}
                </div>
              </div>


              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;">审核状态</label>
                <div class="layui-input-block">
                <input type="radio" name="status"  value="0" title="待审">
                <input type="radio" name="status"  value="1" checked title="通过">
                <input type="radio" name="status"  value="2" title="拒绝" >
                </div>
              </div>


              <div class="layui-form-item">
                <label class="layui-form-label" style="width:100px;"></label>
                <div class="layui-input-inline">
                   <button class="layui-btn layui-btn-normal"  lay-submit lay-filter="form">确 定</button>
                   <button class="layui-btn layui-btn-primary"  onclick="javascript:history.go(-1);">返 回</button>
                </div>
              </div>


</form>
</div>

<script>
layui.use(['element', 'layer','form'], function(){
   var  element = layui.element, layer = layui.layer,form = layui.form;

// 中介交易 
 $('#price').on('keyup',function(){
     money();
 });

 form.on("radio(fee_type)",function(){
    money();

 });
function money()
{
      var fee_type = $("input[name='fee_type']:checked").val();
      if(fee_type < 0){
        layer.msg('请选择中介费支付方式');
        return false;
      }
       var price = $("#price").val(); //价格
       
       var free_ratio = "{$settings.guarantee.fee_ratio}"; //手续费比例
      if(free_ratio <= 0){
        free_ratio = 0;
      }
      price = parseInt(price);
      free_ratio =  parseInt(free_ratio);
       if(price > 0 ){
          var free =  price * (free_ratio/100);
          if(fee_type ==1){
       
            var buyer = '买家支付 <span class="orange">'+ (price+free)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ price+'</span> 元';
            $("#buyer_pay").val(price+free);
            $("#seller_get").val(price);
            $("#result").html(buyer+' '+seller);
          }else if(fee_type ==2){
            var buyer = '买家支付 <span class="orange">'+ (price)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ (price-free)+'</span> 元';
            $("#buyer_pay").val(price);
            $("#seller_get").val(price-free);
            $("#result").html(buyer+' '+seller);
          }else if(fee_type ==3){
            var buyer = '买家支付 <span class="orange">'+ (price+free/2)+'</span> 元';
            var seller= '卖家获得 <span class="orange">'+ (price-free/2)+'</span>元';
            $("#buyer_pay").val(price-free/2);
            $("#seller_get").val(price-free/2);
            $("#result").html(buyer+' '+seller);
          }
         
       }else{
          $("#result").html('<span class="orange">交易价格不能为空</span>');
       }
}


 //监听提交
  form.on('submit(form)', function(data){
    $.post("{:url('guarantee/infoAdd')}",$("form").serialize(),function(json){
        if(json.code == 0){
        qilecms.success(json.msg);
        setTimeout(function(){
         qilecms.back();
        },1000);
        }else{
          qilecms.error(json.msg);
        }
    });
   return false;
  });

//选择发布用户
  $("#choose-user").on('click',function(){
  layer.open({
    type: 2,
    title:'选择卖家',
    shadeClose:true,
    shade: 0.4,
    area: ['650px','90%'],
    maxmin: true, //
    resize:false,
    content: '{:url("user/userSelect")}',
    success: function(layero, index){ 
    var id ='username';
    var body = layer.getChildFrame('body', index);
    body.find('#chooseType').val(id); //找到子iframe 中的dom 元素，传值过去
    }
  }); 
});

});

</script>

</body>

</html>